﻿using RockBus.DataContracts;
using RockBus.Hosting;
using RockBus.Logging.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.ServiceModel.Configuration;
using System.Text;
using System.Threading.Tasks;

namespace RockBus.ServiceBus
{
    public class SubscriberServiceHost : ReceivePortServiceHostBase<SubscriberService>
    {
        public SubscriberServiceHost(ILogger logger, SubscriberService singletonInstance, EndpointInfo endpointInfo)
            : base(logger, endpointInfo)
        {
            this.Logger.LogInfo(MethodBase.GetCurrentMethod(), "Creating SubscriberServiceHost on original address {0}", endpointInfo.Address);

            var baseAddresses = new UriSchemeKeyedCollection();
            foreach (BaseAddressElement baseAddressElement in this.TemplateServiceElement.Host.BaseAddresses)
            {
                baseAddresses.Add(new Uri(baseAddressElement.BaseAddress));
            }

            this.ReceivePortBaseAddresses = baseAddresses.ToArray();

            this.InitializeDescription(singletonInstance, new UriSchemeKeyedCollection());
        }
    }
}
